<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>智慧管家-工作台</title>
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/layuimini.css?v=2.0.4.2" media="all">
    <link rel="stylesheet" href="/css/themes/default.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <link rel="stylesheet" href="/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        /** 应用快捷块样式 */
        .console-app-group {
            padding: 16px;
            border-radius: 4px;
            text-align: center;
            background-color: #fff;
            cursor: pointer;
        }

        .console-app-group .console-app-icon {
            width: 32px;
            height: 32px;
            line-height: 32px;
            margin-bottom: 6px;
            display: inline-block;
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
            font-size: 32px;
            color: #69c0ff;
        }

        .console-app-group:hover {
            box-shadow: 0 0 15px rgba(0, 0, 0, .08);
        }

        /** //应用快捷块样式 */

        /** 小组成员 */
        .console-user-group {
            position: relative;
            padding: 10px 0 10px 60px;
        }

        .console-user-group .console-user-group-head {
            width: 32px;
            height: 32px;
            position: absolute;
            top: 50%;
            left: 12px;
            margin-top: -16px;
        }

        .console-user-group .layui-badge {
            position: absolute;
            top: 50%;
            right: 8px;
            margin-top: -10px;
        }

        .console-user-group .console-user-group-name {
            line-height: 1.2;
        }

        .console-user-group .console-user-group-desc {
            color: #8c8c8c;
            line-height: 1;
            font-size: 12px;
            margin-top: 5px;
        }

        /** 卡片轮播图样式 */
        .admin-carousel .layui-carousel-ind {
            position: absolute;
            top: -41px;
            text-align: right;
        }

        .admin-carousel .layui-carousel-ind ul {
            background: 0 0;
        }

        .admin-carousel .layui-carousel-ind li {
            background-color: #e2e2e2;
        }

        .admin-carousel .layui-carousel-ind li.layui-this {
            background-color: #999;
        }

        /** 广告位轮播图 */
        .admin-news .layui-carousel-ind {
            height: 45px;
        }

        .admin-news a {
            display: block;
            line-height: 60px;
            text-align: center;
            border-radius: 4px;
        }
    </style>
</head>

<body>
<!-- 正文开始 -->
<div class="layui-fluid ew-console-wrapper">
    <div class="layui-row layui-col-space15">

        <div class="layui-col-xs12 layui-col-sm3 layui-col-md3">
            <div class="layui-card">
                <div class="layui-card-header">
                    我的投诉
                    <span class="icon-text pull-right" lay-tips="我的投诉" lay-direction="4" lay-offset="5px,5px">
                            <i class="layui-icon layui-icon-tips"></i>
                        </span>
                </div>
                <div class="layui-card-body">
                    <p class="lay-big-font">${totalMyTouSu}<span style="font-size: 24px;line-height: 1;">个</span>
                    </p>
                    <p>总投诉数量<span class="pull-right">${totalTouSu}个</span></p>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm3 layui-col-md3">
            <div class="layui-card">
                <div class="layui-card-header">
                    我的维修
                    <span class="icon-text pull-right" lay-tips="我的维修" lay-direction="4" lay-offset="5px,5px">
                            <i class="layui-icon layui-icon-tips"></i>
                        </span>
                </div>
                <div class="layui-card-body">
                    <p class="lay-big-font">${totalMyRepair}<span style="font-size: 24px;line-height: 1;">个</span>
                    </p>
                    <p>总维修数量<span class="pull-right">${totalRepair}个</span></p>
                </div>
            </div>
        </div>

        <div class="layui-col-xs12 layui-col-sm3 layui-col-md3">
            <div class="layui-card">
                <div class="layui-card-header">
                    我的账单
                    <span class="icon-text pull-right" lay-tips="我的账单" lay-direction="4" lay-offset="5px,5px">
                            <i class="layui-icon layui-icon-tips"></i>
                        </span>
                </div>
                <div class="layui-card-body">
                    <p class="lay-big-font">${totalMyPayment}<span style="font-size: 24px;line-height: 1;">个</span></p>
                    <p>总帐单数<span class="pull-right">${totalPayment}个</span></p>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm3 layui-col-md3">
            <div class="layui-card">
                <div class="layui-card-header">
                    个人信息
                    <span class="icon-text pull-right" lay-tips="个人信息" lay-direction="4" lay-offset="5px,5px">
                            <i class="layui-icon layui-icon-tips"></i>
                        </span>
                </div>
                <div class="layui-card-body">
                    <p>手机号:${phone};性别:${sex}</p>
                    <p>房屋:${myUserRoom}</p>
                    <p>车位:${myUserCar}</p>
                </div>
            </div>
        </div>
    </div>
    <!-- 快捷方式 -->
    <div class="layui-row layui-col-space15">
        <div class="layui-col-sm6" style="padding-bottom: 0;">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-xs6 layui-col-sm3">
                    <div class="console-app-group" id="newTousu">
                        <i class="console-app-icon layui-icon layui-icon-group"
                           style="font-size: 26px;padding-top: 3px;margin-right: 6px;"></i>
                        <div class="console-app-name">添加投诉</div>
                    </div>
                </div>
                <div class="layui-col-xs6 layui-col-sm3">
                    <div class="console-app-group" id="newRepair">
                        <i class="console-app-icon layui-icon layui-icon-chart" style="color: #95de64;"></i>
                        <div class="console-app-name">添加维修</div>
                    </div>
                </div>
                <div class="layui-col-xs6 layui-col-sm3"  >
                    <div class="console-app-group" id="look" lay-event="zhangDan">
                        <i class="console-app-icon layui-icon layui-icon-cart" style="color: #95de64;"></i><span
                            class="layui-badge-dot"></span>
                        <div class="console-app-name">查看账单</div>
                    </div>
                </div>
                <div class="layui-col-xs6 layui-col-sm3" lay-submit lay-filter="data-updatepwd-btn">
                    <div class="console-app-group" ew-event="reset_user">
                        <i class="console-app-icon layui-icon layui-icon-password" style="color: #ff9c6e;"></i>
                        <div class="console-app-name">修改密码</div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-sm6" style="padding-bottom: 0;">
            <div class="layui-card">
                <div class="layui-card-body" style="padding: 17px 15px;">
                    <table id="gonggao" lay-filter="gonggao"></table>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row layui-col-space15">
        <div class="layui-col-lg6 layui-col-md6">
            <div class="layui-card">
                <div class="layui-card-header">我的投诉</div>
                <div class="layui-card-body" style="padding: 17px 15px;">
                    <!-- 我的投诉表格 -->
                    <table id="tousu" lay-filter="gonggao"></table>
                </div>
            </div>
        </div>
        <div class="layui-col-lg6 layui-col-md6">
            <div class="layui-card">
                <div class="layui-card-header">我的维修</div>
                <div class="layui-card-body" style="padding: 17px 15px;">
                    <!-- 我的维修表格 -->
                    <table id="weixiu" lay-filter="gonggao"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="modelAddTouSu">
    <form id="modelAddTouSuForms" lay-filter="modelAddForm" class="layui-form model-form">
        <div class="layui-form-item">
            <label class="layui-form-label">投诉内容</label>
            <div class="layui-input-block">
                <input name="content" placeholder="投诉内容" type="text" class="layui-input" maxlength="20"
                       lay-verType="tips" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-primary" type="reset">重置</button>
                <button class="layui-btn" lay-filter="modelSubmitAdd" lay-submit>保存</button>
            </div>
        </div>
    </form>
</script>
<script type="text/html" id="modelAddWeiXiu">
    <form id="modelAddWeiXiuForms" lay-filter="modelAddForm" class="layui-form model-form">
        <div class="layui-form-item">
            <label class="layui-form-label">维修内容</label>
            <div class="layui-input-block">
                <input name="content" placeholder="维修内容" type="text" class="layui-input" maxlength="20"
                       lay-verType="tips" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-primary" type="reset">重置</button>
                <button class="layui-btn" lay-filter="modelSubmitAdd" lay-submit>保存</button>
            </div>
        </div>
    </form>
</script>
<%--密码修改--%>
<script type="text/html" id="modelupdate">
    <form id="modelAddForms" lay-filter="modelAddForm" class="layui-form model-form">
        <div class="layui-form-item">
            <label class="layui-form-label">原始密码</label>
            <div class="layui-input-block">
                <input name="oldpwd" placeholder="请输入原始密码" type="password" class="layui-input" maxlength="20"
                       lay-verType="tips" lay-verify="required" required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input name="newpwd1" id="newpwd" placeholder="请输入新密码密码" type="password" class="layui-input"
                       maxlength="20"
                       lay-verType="tips" lay-verify="required" required/>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input name="newpwd2" placeholder="请再次确认新密码" type="password" class="layui-input" maxlength="20"
                       lay-verType="tips" lay-verify="required" required/>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-primary" type="reset" id="closeBtn">重置</button>
                <button class="layui-btn" lay-filter="modelSubmitupdate" lay-submit>保存</button>
            </div>
        </div>
    </form>
</script>
<script type="text/html" id="currentTableinfo">
    <table class="layui-hide" id="information" lay-filter="information"></table>
</script>

<script type="text/html" id="currentTableBar">
    {{#  if(d.status === 0){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs data-count-edit" lay-event="pay">在线缴费</a>
    {{#  } }}

</script>
<!-- 加载动画 -->
<div class="page-loading">
    <div class="ball-loader">
        <span></span><span></span><span></span><span></span>
    </div>
</div>

<!-- js部分 -->
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script src="/js/sessionTimout.js" charset="utf-8"></script>
<script>

    layui.use(['layer', 'util', 'table', 'form'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var util = layui.util;
        var form = layui.form;
        var table = layui.table;
        //加载投诉列表
        table.render({
            elem: '#tousu',
            url: '/UserServlet?opt=TouSuList',
            cols: [[
                {title: 'ID', field: 'id', type: 'numbers'},
                {field: 'content', title: '投诉内容', sort: true},
                {field: 'time', title: '发布时间', sort: true},
                {field: 'result', title: '处理结果', sort: true},
                {
                    field: 'status', title: '状态', sort: true, templet: function (row) {
                        if (row.status == 0) {
                            return '<input type="checkbox" lay-text="已处理|未处理" lay-skin="switch" checked disabled>'
                        } else {
                            return '<input type="checkbox" lay-text="已处理|未处理" lay-skin="switch" disabled>'
                        }
                    }
                },
            ]],
            limits: [2, 4, 6, 8, 10],
            limit: 2,
            page: true,
            skin: 'line'
        });
        // 加载维修列表
        table.render({
            elem: '#weixiu',
            url: '/UserServlet?opt=WeiXiuList',
            cols: [[
                {title: 'ID', field: 'id', type: 'numbers'},
                {field: 'content', title: '维修内容', sort: true},
                {field: 'time', title: '发布时间', sort: true},
                {field: 'result', title: '维修结果', sort: true},
                {
                    field: 'status', title: '状态', sort: true, templet: function (row) {
                        if (row.status == 1) {
                            return '<input type="checkbox" lay-text="已处理|未处理" lay-skin="switch" checked disabled>'
                        } else {
                            return '<input type="checkbox" lay-text="已处理|未处理" lay-skin="switch" disabled>'
                        }
                    }
                },
            ]],
            limits: [2, 4, 6, 8, 10],
            limit: 2,
            page: true,
            skin: 'line'
        });
        // 加载公告列表
        // 表格渲染
        table.render({
            elem: '#gonggao',
            url: '/UserServlet?opt=gongGaoList',
            cols: [[
                {title: 'ID', field: 'id', type: 'numbers'},
                {field: 'title', title: '公告标题', sort: true},
                {field: 'content', title: '公告内容', sort: true},
            ]],
            limits: [2, 4, 6, 8, 10],
            limit: 2,
            page: true,
            skin: 'line'
        });
        // 添加维修
        $('#newRepair').click(function () {
            // 弹出层
            layer.open({
                type: 1,
                title: '添加维修',
                content: $('#modelAddWeiXiu').html(),
                success: function (layero, dIndex) {
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    // 表单提交事件
                    form.render();
                    form.on('submit(modelSubmitAdd)', function (data) {  // 表单数据对象
                        layer.load(2);
                        $.ajax({
                            url: '/UserServlet?opt=addWeiXiu',
                            type: "POST",
                            data: data.field,
                            dataType: "json",
                            success: function (data) {
                                layer.closeAll('loading');
                                if (data.code == 0) {
                                    layer.close(dIndex);
                                    layer.msg(data.msg, {icon: 1});
                                    // 刷新表格
                                    //执行搜索重载
                                    table.reload('weixiu')
                                } else {
                                    layer.msg(data.msg, {icon: 2});
                                }
                            }
                        })
                        return false;
                    });
                }
            });
        });

        // 添加投诉
        $('#newTousu').click(function () {
            layer.open({
                type: 1,
                title: '添加投诉',
                content: $('#modelAddTouSu').html(),
                success: function (layero, dIndex) {
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    // 表单提交事件
                    form.render();
                    form.on('submit(modelSubmitAdd)', function (data) {  // 表单数据对象
                        layer.load(2);
                        $.ajax({
                            url: '/UserServlet?opt=addTouSu',
                            type: "POST",
                            data: data.field,
                            dataType: "json",
                            success: function (data) {
                                layer.closeAll('loading');
                                if (data.code == 0) {
                                    layer.close(dIndex);
                                    layer.msg(data.msg, {icon: 1});

                                    // 刷新表格
                                    //执行搜索重载
                                    table.reload('tousu')
                                } else {
                                    layer.msg(data.msg, {icon: 2});
                                }
                            }
                        })
                        return false;
                    });
                }
            });
        });
        //修改密码
        form.on('submit(data-updatepwd-btn)', function (data) {  // data 表单数据对象 name键 value值
            // 打开添加对话框
            showAddModel();
            return false;
        });

        function showAddModel(data) {
            // 打开弹窗
            layer.open({
                type: 1,
                title: '修改密码',
                content: $('#modelupdate').html(),
                success: function (layero, dIndex) {
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');

                    // 表单提交事件
                    form.render();
                    form.on('submit(modelSubmitupdate)', function (data) {  // 表单数据对象
                        let pwd = document.getElementById("newpwd");
                        let pwdValue = pwd.value;
                        let reg = /^[a-zA-Z0-9]{4,15}$/;
                        if (reg.test(pwdValue) == false) {
                            layer.msg("密码不能含有非法字符，长度在4-15之间!")
                            return false;
                        }
                        layer.load(2);
                        $.ajax({
                            url: '/UserServlet?opt=updatePwd',
                            type: "POST",
                            data: data.field,
                            dataType: "json",
                            success: function (data) {
                                layer.closeAll('loading');
                                if (data.code == 0) {
                                    layer.close(dIndex);
                                    layer.msg(data.msg, {icon: 1});
                                    layer.confirm('密码修改成功,请重新登录!', {
                                        btn: ['重新登录'] //按钮
                                    }, function () {
                                        parent.location.href='/page/user/userLogin.jsp'
                                    });

                                } else {
                                    layer.msg(data.msg, {icon: 2});
                                }

                            }
                        })
                        return false;
                    });
                }
            });
        }

        // 查看缴费
            $('#look').click(function () {
                var $a = $('#look');
                var offset = $a.offset();
                layer.open({
                    type: 1,
                    area: '590px',
                    offset: ['100px', (offset.left - 160 + $a.outerWidth()) + 'px'],
                    content: $('#currentTableinfo').html(),
                    success: function (layero, dIndex) {
                        table.render({
                            elem: '#information',
                            url: '/UserServlet?opt=zhangdan',
                            cols: [[
                                {title: 'ID', field: 'id', type: 'numbers'},
                                {field: 'paymentname', title: '缴费名称', sort: true},
                                {field: 'username', title: '用户名称', sort: true},
                                {field: 'value', title: '缴费金额', sort: true},
                                {field: 'time', title: '缴费时间', sort: true},
                                {
                                    field: 'status', title: '缴费状态', templet: function (row) {
                                        return `<input type="checkbox" lay-text="已缴费|未缴费" lay-skin="switch" \${row.status==1?'checked':''} disabled>`
                                    }
                                },
                                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
                            ]],
                            limits: [2, 4, 6, 8, 10],
                            limit: 2,
                            page: true,
                            skin: 'line'
                        });
                        table.on('tool(information)', function (obj) {
                            let data = obj.data;
                            if (obj.event === 'pay') {
                                console.log(1)
                                window.open(`/PayServlet?opt=pay&id=\${data.id}`)

                                layer.confirm('是否支付?', {
                                    btn: ['是', '否'] //按钮
                                }, function () {
                                    layer.closeAll('dialog'); // 关闭所有的信息框
                                    table.reload('information')
                                }, function () {
                                    layer.closeAll('dialog'); // 关闭所有的信息框
                                    table.reload('information')
                                });
                                return false;
                            }
                        });
                    }
                });
            });
    });
</script>
</body>

</html>
